﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using System.Net.Mail;
using WWF.Contracts;

namespace WWF.Activities
{

    public sealed class NotifyApplicant : CodeActivity
    {
        // Define an activity input argument of type string
        public InArgument<string> StatusRequest { get; set; }
        public InArgument<ApplicationRequest> ApplicationRequest { get; set; }

        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        protected override void Execute(CodeActivityContext context)
        {
            string status = context.GetValue(StatusRequest);
            ApplicationRequest applicationRequest = context.GetValue(ApplicationRequest);
            string mailSubject = "";
            string mailText = "";
            switch (status)
            {
                case "Waiting for Interview":
                    mailSubject = Resources.InterviewMailSubject;
                    mailText = string.Format(Resources.MailTemplate, mailSubject, string.Format(Resources.InterviewInvitation, applicationRequest.ApplicantName));
                    break;
                case "Accepted":
                    mailSubject = Resources.AcceptanceMailSubject;
                    mailText = string.Format(Resources.MailTemplate, mailSubject, string.Format(Resources.AcceptanceLetter, applicationRequest.ApplicantName));
                    break;
                case "Rejected":
                    mailSubject = Resources.RejectionMailSubject;
                    mailText = string.Format(Resources.MailTemplate, mailSubject, string.Format(Resources.RejectionLetter, applicationRequest.ApplicantName));
                    break;
            }

            SmtpClient smtpClient = new SmtpClient();
            MailMessage msg = new MailMessage("application@iss.nus.edu.sg", applicationRequest.ApplicantEmail, mailSubject, mailText);
            msg.IsBodyHtml = true;
            smtpClient.Send(msg);
        }
    }
}
